# Maintainer: Celeste <cielesti@protonmail.com>
maintainer="Celeste <cielesti@protonmail.com>"
pkgname=tcl9
pkgver=9.0.0
pkgrel=0
_major=${pkgver%.*}
pkgdesc="The Tcl scripting language, version 9"
url="https://www.tcl-lang.org/"
arch="all"
license="TCL"
depends="tzdata"
depends_dev="
	$pkgname=$pkgver-r$pkgrel
	zip
	"
makedepends="
	$depends_dev
	bsd-compat-headers
	sqlite-dev
	zlib-dev
	"
subpackages="$pkgname-dev $pkgname-doc"
source="https://downloads.sourceforge.net/sourceforge/tcl/tcl$pkgver-src.tar.gz
	tclsqlite-include-stdint.patch
	"
builddir="$srcdir/tcl$pkgver/unix"
options="net" # tests require networking

prepare() {
	local builddir="$srcdir/tcl$pkgver"

	default_prepare
}

build() {
	case "$CARCH" in
		arm*|x86)	_64bit="--disable-64bit" ;;
		*)		_64bit="--enable-64bit"  ;;
	esac

	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var \
		--with-system-sqlite \
		--disable-rpath \
		--disable-zipfs \
		$_64bit
	make
}

check() {
	# thread-4.5 and thread-5.2 are suppressed because they test UB
	# lseq-1.27 is suppressed as it gets stuck in a loop on non-x86
	make test TESTFLAGS="-verbose pbtels -skip 'thread-4.5 thread-5.2 lseq-1.27'"
}

package() {
	make INSTALL_ROOT="$pkgdir" install install-private-headers

	ln -sf tclsh$_major "$pkgdir"/usr/bin/tclsh9
	install -Dm644 ../license.terms \
		"$pkgdir"/usr/share/licenses/$pkgname/LICENSE

	# remove buildroot traces
	find "$pkgdir" -name '*Config.sh' -print0 |
		xargs -0 sed -i -e "s#${srcdir}#/usr/src#"

	# prevent conflict with main/sqlite-tools
	rm -v "$pkgdir"/usr/bin/sqlite3_analyzer
}

dev() {
	default_dev

	local file; find "$pkgdir" -name '*Config.sh' | while read -r file; do
		amove "${file#"$pkgdir"}"
	done
}

sha512sums="
d7c1527b0346081df43a0df76ddac01d7a2bf6f626a0f1bed3db77bbd4efaa645dd2ff7c16354522ee9150d82581466b4b59718d3b10fda51de2ec03ed9459ad  tcl9.0.0-src.tar.gz
9bfe2946baedeedbb70c6c18273b137772b0539e5ce6a0aea04f6df59ff463eb6b4da93723d8b84d7faf0861a18e0e82038582c457e959284b3cf314c18ca7cb  tclsqlite-include-stdint.patch
"
